package cn.wit.testalgorithms;

import java.util.Arrays;

/**
 * 495.提莫攻击
 * 
 * @author 16604
 *
 */
public class DemoTimothyAttack {
	public static void main(String[] args) {

		int[] a = { 1, 2, 4, 5 };
		int k = 5;

		System.out.println(findPoisonedDuration(a, k));

	}

	public static int findPoisonedDuration(int[] timeSeries, int duration) {

		if (timeSeries.length <= 0)
			return 0;

		int sum = 0;
		for (int i = 1; i < timeSeries.length; i++) {
			if (timeSeries[i] - timeSeries[i - 1] >= duration)
				sum += duration;
			else
				sum += timeSeries[i] - timeSeries[i - 1];
		}
		sum += duration;
		return sum;

	}

}
